//根据提供的头文件标准规范，用所学过的类和对象的知识，封装log4cpp         
//实现一个单例的效果。能够输出到终端，还能保存到文件。让其使用起来更方便
//要求：可以像printf一样，同时输出的日志信息中最好能有文件的名字
//函数的名字及其所在的行号
#ifndef LOGGER_H
#define LOGGER_H
#include <iostream>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Category.hh>
using namespace std;
using namespace log4cpp;

#define LOG_WARN(msg) Logger::getInstance()->warn(__FILE__,__LINE__,__FUNCTION__,msg)
#define LOG_ERROR(msg) Logger::getInstance()->error(__FILE__,__LINE__,__FUNCTION__,msg)
#define LOG_DEBUG(msg) Logger::getInstance()->debug(__FILE__,__LINE__,__FUNCTION__,msg)
#define LOG_INFO(msg) Logger::getInstance()->info(__FILE__,__LINE__,__FUNCTION__,msg)

class Logger{
public:
    void warn(const char * file, int line, const char * func, const char * msg);
    void error(const char * file, int line, const char * func, const char * msg);
    void debug(const char * file, int line, const char * func, const char * msg);
    void info(const char * file, int line, const char * func, const char * msg);

    static Logger * getInstance();

    static void destory();


private:
    Logger();
    ~Logger();

    Logger(const Logger &) = delete;
    Logger & operator=(const Logger &) = delete;

    static Logger * _pInstance;
     Category & _root;
};

#endif

